<?php
if(isset($_POST['del']) && !empty($_POST['del'])){
    $del_arr = $_POST['del'];
    $original_ids = implode(",", $del_arr);
    $ret = array();
    $rs = getdb("select user_id from bet where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_3s3 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_3s5 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_8h where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_8h2 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_8h3 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_pk10 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_sb1 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $rs = getdb("select user_id from bet_sb2 where user_id in (".$original_ids.")");
    while (!$rs->eof) {
        $ret[] = $rs->f['user_id'];
        $rs->movenext();
    }
    $end_arr = array_unique($ret);
    $success_count = count($del_arr);
    $end_str = "";
    if(count($end_arr) > 0){
        $success_count = count($del_arr) - count($end_arr);
        $end_ids = implode(",", $end_arr);
        $end_str = " and id not in (".$end_ids.")";
    }
    getdb("delete from k_user where id in (".$original_ids.")".$end_str);
    echo "<script>alert('删除用户成功".$success_count."条，删除失败".count($end_arr)."条！');window.location='op.php?op=agent&fp=member&gametype=0&page=1&enabled=1&prev_id=0'</script>";
}else if(isset($_POST['del'])){
    echo "<script>alert('删除失败，请指定删除用户！');window.location='op.php?op=agent&fp=member&gametype=0&page=1&enabled=1&prev_id=0'</script>";
}
function member_list ($gametype)
{
    global $acl;
    global $user;
    global $curruser;
    global $funlist;
    global $conf;
    global $g_disk_name;
    global $g_gametype_3d;
    global $g_init_mode_6h;
    global $g_init_mode_3d;
    global $g_disk_codeUP;
    $timeCheck = systime() - 2592000;
    $enabled = getvar("enabled");
    if ($enabled == "")
    {
        $enabled = 1;
    }
    $qctmp = "enabled>0";
    if ($enabled == 0)
    {
        $qctmp = "enabled=0";
    }
    $prev_id = isset($_GET['prev_id']) ? intval($_GET['prev_id']) : 0;
    echo "<form name=delete_user_form method=post action=op.php?".$_SERVER['QUERY_STRING'].">";
    echo "<table bgcolor=#B3B3B3 border=0 cellpadding=0 cellspacing=1 width=758><tr><td>" . "<table class=table0 width='100%' border=0 cellpadding=0 cellspacing=0><tr><td class='title0 bgImg_{$gametype}'>" . "<table width=100% border=0 cellpadding=1 cellspacing=0><tr><td>" . L_MEMBERINFO . " " . ( $enabled == 0 ? L_DISABLE : L_ENABLE ) . " " . L_LIST . "<td align=right>" . $funlist . "</table></table></table>";
    $page = intval(getvar("page"));
    if ($page == 0)
    {
        $page = 1;
    }
    $reat0_open = $conf->get("reat0_open");
    $sql = "select * from k_user where acl=" . $acl . " and " . $qctmp;
    if ($curruser['acl'] == 2)
    {
        $sql .= " and prev_id=" . $curruser['id'];
    }
    else if ($curruser['acl'] < 255)
    {
        $users = getuserlist($curruser['id'], 1, $enabled);
        if ($users == "")
        {
            $sql .= " and 1=0";
        }
        else
        {
            $sql .= " and id in (" . $users . ")";
        }
    }
    if (0 < $prev_id)
    {
        $sql .= " and prev_id=" . $prev_id;
    }
    $sql .= " order by account";
    $rs = getdb($sql, $page);
    if ($rs->eof)
    {
        echo "<p><font color=red>" . L_NOMEMBERS . "</font></p>";
    }
    else
    {
        if (get_rate0_mode($rs->f['id']) == 0)
        {
            $reat0_open = 0;
        }
        echo "<table width=758 border=1 cellspacing=1 cellpadding=0 class=\"mytable\">";
        echo "<tr class='td0 bgClc_{$gametype}' align=center>\r\n\t\t<td nowrap>代理商</td>\r\n\t\t<td nowra>会员帐号</td>\r\n\t\t<td nowrap>名称</td>\r\n\t\t<td nowrap>盘类</td>";
        echo "<td nowrap>信用额度</td>";
		if ($reat0_open)
		{
			echo "<td nowrap>减倍</td>";
		}
		echo "<td nowrap>代理占成</td>";
		echo "<td nowrap>新增/更新</td>\r\n\t\t<td nowrap>最後登入</td>\r\n\t\t<td nowrap>最後登入IP</td>\r\n\t\t<td nowrap>状况</td>\r\n\t\t<td nowrap>功能设定</td>\r\n\t\t<td nowrap>是否删除</td>\r\n\t\t</tr>";
        while (!$rs->eof)
        {
            echo "<tr class=td2 onmouseover=msover() onmouseout=msout()>";
            $user1 = get_user($rs->f['prev_id'], 0);
			$user2 = get_user($rs->f['prev_id'], 12);
            echo "<td nowrap>" . $user1['account'];
            if ($timeCheck < $rs->f['createdt'])
            {
                $tempClass = " class=\"td4\" ";
            }
            else
            {
                $tempClass = "";
            }
            echo "<td nowrap {$tempClass}><a href='?op=agent&fp=member&gametype=" . $gametype . "&cmd=edit&id=" . $rs->f['id'] . "' >" . $rs->f['account'] . "</a>";
            echo "<td nowrap>" . $rs->f['name'];
            $tempDiskArr = array();
            if ($rs->f['disk1'])
            {
                $tempDiskArr[] = $g_disk_codeUP[1];
            }
            if ($rs->f['disk2'])
            {
                $tempDiskArr[] = $g_disk_codeUP[2];
            }
            if ($rs->f['disk3'])
            {
                $tempDiskArr[] = $g_disk_codeUP[3];
            }
            if ($rs->f['disk4'])
            {
                $tempDiskArr[] = $g_disk_codeUP[4];
            }
            echo "<td nowrap>" . implode("", $tempDiskArr) . "盘";
            if (0 < $gametype)
            {
                if ($rs->f['amount_type'] == 1)
                {
                    echo "<td nowrap align=right><font color='#1111AA'>" . n_to_c($rs->f['amount']) . "</font>";
                }
                else
                {
                    echo "<td align=right nowrap>" . n_to_c($rs->f['amount']);
                }
                echo "<td nowrap align=right>(6h)" . $user1['mpercent'] . "%/<font color=#0000ff>(快)" . $user2['mpercent'] . "%</font></td>";
            }
            else
            {
                echo "<td nowrap align=right>" . n_to_c($rs->f['amount']);
                if ($reat0_open)
                {
                    echo "<td nowrap align=right>" . $rs->f['rate0'];
                }
                echo "<td nowrap align=right>(6h)" . $user1['mpercent'] . "%/<font color=#0000ff>(快)" . $user2['mpercent'] . "%</font></td>";
            }
            echo "<td nowrap>" . ( $rs->f['updatedt'] == "" ? date("Y-m-d", $rs->f['createdt']) : date("Y-m-d", $rs->f['updatedt']) );
            echo "<td nowrap>" . ( $rs->f['lastlogdt'] == "" ? "" : date("Y-m-d", $rs->f['lastlogdt']) );
            echo "<td nowrap>" . $rs->f['lastlogip'];
            if ($rs->f['enabled'] == 1)
            {
                echo "<td align=center nowrap>" . L_ENABLE;
            }
            else if ($rs->f['enabled'] == 2)
            {
                echo "<td align=center bgcolor=red nowrap><font color=white>暂停</font>";
            }
            else
            {
                echo "<td align=center bgcolor=black nowrap><font color=white>" . L_DISABLE . "</font>";
            }
            echo "<td nowrap><a href='?op=agent&fp=member&gametype=" . $gametype . "&cmd=edit&id=" . $rs->f['id'] . "'>修改</a> ";
            echo ":: <a href='?op=agent&fp=amount2_3d&gametype=" . $gametype . "&id=" . $rs->f['id'] . "'>限额</a> ";
            echo "<td align=center><input type='checkbox' name='del[]' value=".$rs->f['id']." />";
            $rs->next();
        }
        echo "<tr class='td0 bgClc_{$gametype}'><td colspan=11>";
        if (1 < $page)
        {
            echo "<a class=td0 href='?op=agent&fp=member&gametype=" . $gametype . "&page=1&enabled=" . $enabled . "&prev_id=" . $prev_id . "'>" . L_FIRSTPAGE . "</a> &nbsp; ";
            echo "<a class=td0 href='?op=agent&fp=member&gametype=" . $gametype . "&page=" . ( $page - 1 ) . "&enabled=" . $enabled . "&prev_id=" . $prev_id . "'>" . L_PREVPAGE . "</a> &nbsp; ";
        }
        else
        {
            echo L_FIRSTPAGE . " &nbsp; " . L_PREVPAGE . " &nbsp; ";
        }
        if ($page < $rs->totalpages)
        {
            echo "<a class=td0 href='?op=agent&fp=member&gametype=" . $gametype . "&page=" . ( $page + 1 ) . "&enabled=" . $enabled . "&prev_id=" . $prev_id . "'>" . L_NEXTPAGE . "</a> &nbsp; ";
            echo "<a class=td0 href='?op=agent&fp=member&gametype=" . $gametype . "&page=" . $rs->totalpages . "&enabled=" . $enabled . "&prev_id=" . $prev_id . "'>" . L_LASTPAGE . "</a> &nbsp; ";
        }
        else
        {
            echo L_NEXTPAGE . " &nbsp; " . L_LASTPAGE . " &nbsp; ";
        }
        echo " &nbsp; &nbsp; " . L_PAGE . " <select onchange=\"location.href='op.php?op=" . $_GET['op'] . "&fp=" . $_GET['fp'] . "&gametype=" . $gametype . "&enabled=" . $enabled . "&prev_id=" . $prev_id . "&page=' + this.value\">";
        $i = 1;
        while ($i <= $rs->totalpages)
        {
            echo "<option value=" . $i;
            if ($page == $i)
            {
                echo " selected";
            }
            echo ">" . $i;
            ++$i;
        }
        echo "</select>";
        echo "，总共 " . $rs->totalpages . " 页，" . $rs->totalrecords . " " . L_RECORDERS;
        $prev_id = isset($_GET['prev_id']) ? intval($_GET['prev_id']) : 0;
        $gametype = isset($_GET['gametype']) ? intval($_GET['gametype']) : 0;
        echo "<td> <input type=\"hidden\" name=\"op\" value=\"agent\"/><input type=\"hidden\" name=\"fp\" value=\"member\"/><input type=\"hidden\" name=\"prev_id\" value=".$prev_id." /><input type=\"hidden\" name=\"gametype\" value=".$gametype."/> <input type=\"submit\" value=\"删除\"/>";
        echo "</table>";
        echo "</form>";
        $rs->close();
    }
}

function member_edit ($gametype)
{
    global $acl;
    global $user;
    global $curruser;
    global $funlist;
    global $conf;
    global $g_cache;
    global $g_conf;
    global $g_disk_name;
    global $g_gametype_3d;
    global $g_init_mode_6h;
    global $g_init_mode_3d;
    global $g_menu_enabled;
    global $aclname;
    $amount_type_mod_chg_flag = true;
    $amount_type_mod_chg_str = "";
    $id = intval(getvar("id"));
    include_once( "class/class.acctMag.php" );
    include_once( "class/class.disk.php" );
    $fg = new Flag();
    $stbl = new Show_member();
    $disk_chg = new disk();
    $psen_edit_mod_Arr = array();
    $lotto_id_Arr = array();
    $open = date("Y-m-d");
    foreach ($g_gametype_3d as $gameid => $val)
    {
        $ary = $fg->swth_control($gameid);
        $psen_edit_mod_Arr[$gameid] = $ary[0];
        $lotto_id_Arr[$gameid] = $ary[1];
        if ($g_init_mode_3d && $gameid == 5 && $g_menu_enabled[$gameid])
        {
            $open = $ary[2];
        }
    }
    $superadmin = $curruser['account'] == G_SUPERACCOUNT && $curruser['acl'] == 255 ? 1 : 0;
    echo "<table bgcolor=#B3B3B3 border=0 cellpadding=0 cellspacing=1 width=758><tr><td>" . "<table class=table0 width='100%' border=0 cellpadding=0 cellspacing=0><tr><td class='title0 bgImg_{$gametype}'>" . "<table width=100% border=0 cellpadding=1 cellspacing=0><tr><td>" . L_MEMBERINFO . " " . ( 0 < $id ? L_EDIT : L_ADD ) . "<td align=right>" . $funlist . "</table></table></table>";
    if (0 < $id)
    {
        if ($curruser['acl'] < 2)
        {
            diemsg(L_NOACCESSEDIT);
        }
        if ($curruser['acl'] < 255)
        {
            $users = getuserlist($curruser['id']);
            if ($users == "")
            {
                diemsg(L_NOTURMEMBER);
            }
            if (strpos("," . $users . ",", "," . $id . ",") === false)
            {
                diemsg(L_NOTURMEMBER);
            }
        }
    }
    $reat0_open = $conf->get("reat0_open");
    $max_rate0 = floatval($conf->Get("max_rate0"));
    $member_limit = intval($conf->get("member_limit")) * ( defined("G_MEMBER_MAX") ? G_MEMBER_MAX : 3 );
    if (isset($_GET['prev_id']))
    {
        $prev_id = intval($_GET['prev_id']);
    }
    else if (isset($_POST['prev_id']))
    {
        $prev_id = intval($_POST['prev_id']);
    }
    else
    {
        $prev_id = 0;
    }
    if ($prev_id == 0 && $curruser['acl'] == 2)
    {
        $prev_id = $curruser['id'];
    }
    if ($prev_id == 0 && 0 < $id)
    {
        $u1 = get_user($id);
        $prev_id = $u1['prev_id'];
    }
    if ($id == 0 && $prev_id == 0)
    {
        echo "<p>请选择上层代理：</p><p><table border=0 cellpadding=2 cellspacing=1 class=table0>";
        echo "<tr class=td0><td nowrap>帐号<td nowrap>名称";
        $rs9 = false;
        if ($curruser['acl'] < 255)
        {
            $users9 = getuserlist($curruser['id'], 2);
            if ($users9 != "")
            {
                $rs9 = getdb("select id,account,name from k_user where id in (" . $users9 . ") and enabled=1 order by account");
            }
        }
        else
        {
            $rs9 = getdb("select id,account,name from k_user where acl=2 and enabled=1 order by account");
        }
        if ($rs9)
        {
            $prev_id_count = 0;
            $first_prev_id = 0;
            while (!$rs9->eof)
            {
                ++$prev_id_count;
                if ($first_prev_id == 0)
                {
                    $first_prev_id = $rs9->f['id'];
                }
                echo "<tr class=td2>";
                echo "<td nowrap><a href=\"op.php?op=agent&fp=member&gametype=" . $gametype . "&cmd=add&prev_id=" . $rs9->f['id'] . "\">" . $rs9->f['account'] . "</a><td>" . $rs9->f['name'];
                $rs9->movenext();
            }
            $rs9->close();
            if ($prev_id_count == 1)
            {
                redirect("op.php?op=agent&fp=member&gametype=" . $gametype . "&cmd=add&prev_id=" . $first_prev_id);
            }
        }
        else
        {
            echo "<tr><td colspane=2>没有代理！";
        }
        echo "</table></p>";
        echo "<script>function newuser(id) {location.replace('op.php?op=agent&fp=member&gametype=" . $gametype . "&cmd=add&prev_id='+id);}</script>";
    }
    else
    {
        $u_prev = get_user($prev_id);
        if ($u_prev['acl'] != 2)
        {
            $user->logout();
            exit();
        }
        if (get_rate0_mode($u_prev['id']) == 0)
        {
            $reat0_open = 0;
        }
        $tpl = new Template2();
        $tpl->load("main", "member.htm");
        $u_prev_percent_Arr = getUserPercents($prev_id);
        $rs = getdb("select count(id) from k_user where acl=1 and enabled=1");
        $tot_acl_1 = $rs->f[0];
        $rs->close();
        $maxamount_Arr = array();
        if (0 < $id)
        {
            $maxamount_Arr['6h'] = GetMyAmount($id);
            $maxamount_Arr['3d'] = $maxamount_Arr['6h'];
            $maxamount_Arr['3s'] = $maxamount_Arr['6h'];
        }
        else if (0 < $prev_id)
        {
            $maxamount_Arr['6h'] = GetMyFreeAmount($prev_id);
            $maxamount_Arr['3d'] = $maxamount_Arr['6h'];
            $maxamount_Arr['3s'] = $maxamount_Arr['6h'];
        }
        else
        {
            exit();
        }
        if (ispost() && SubAccountRight($curruser, 2) == 2)
        {
            $enabled = intval(getvar("enabled"));
            $amount_Arr = array("6h" => 0, "3d" => 0, "3s" => 0);
            $rate0 = 0;
            $amount_used_Arr = array();
            $mbr_disabled_chk = getvar("mbr_disabled") ? 1 : 0;
            $amount_type = getvar("amount_type")?1:0;
            $account = getvar("account");
            $name = getvar("name");
            if ($name == "")
            {
                $name = $account;
            }
            if ($name == "")
            {
                diemsg(L_PLEASEINPUTNAME);
            }
            /*if ($g_conf['language'] == "zh-cn")
            {
                include_once( "class/ccharset.php" );
                $cc = new CCharset();
                $name = $cc->Gb_big5($name);
            }*/
            if (0 < $id)
            {
                $pass = getvar("pass");
                if ($pass != "")
                {
                    if (G_ACCOUNT == 0)
                    {
                        if (!ctype_alnum($pass))
                        {
                            diemsg("密码只能输入A-Z,a-z,0-9的字元！");
                        }
                        if (!check_account_legal($pass))
                        {
                            diemsg("密码必须为６个以上的英文字母及数字混和所组成！（请注意英文大小写）");
                        }
                    }
                    else
                    {
                        $pass = chk_pass($pass);
                    }
                }
                $chk3DFlagArr = array("enabled" => 0, "totalAmounts" => 0);
                $chk3SFlagArr = array("enabled" => 0, "totalAmounts" => 0);
				$amount_Arr['6h'] = intval(getvar("amount"));
                foreach ($g_gametype_3d as $gameid => $val)
                {
                    if ($g_init_mode_6h && $gameid == 0)
                    {
                        $rate0 = floatval(getvar("rate0"));
                        if ($rate0 < 0)
                        {
                            $rate0 = 0 - $rate0;
                        }
                        $rate0 = min($rate0, $max_rate0);
                        if ($reat0_open == 0)
                        {
                            $rate0 = 0;
                        }
                    }
                    else if ($g_init_mode_3d && $gameid)
                    {
                        switch ($gameid)
                        {
                            case 1 :
                            case 2 :
                                $amount_Arr['3d'] = intval(getvar("amount_3d"));
                                break;
                            default :
                                $amount_Arr['3s'] = intval(getvar("amount_3s1"));
                                break;
                        }
                    }
                    if ($psen_edit_mod_Arr[$gameid] == 0)
                    {
                        $amount_used_Arr[$gameid] = getAmount_isused($id, $gameid, $lotto_id_Arr[$gameid]);
                    }
                    else
                    {
                        $amount_used_Arr[$gameid] = 0;
                    }
                    if ($val['type'] == 1)
                    {
                        $chk3DFlagArr['enabled'] = 1;
                        $chk3DFlagArr['totalAmounts'] += $amount_used_Arr[$gameid];
                    }
                    else if (1 < $val['type'])
                    {
                        $chk3SFlagArr['enabled'] = 1;
                        $chk3SFlagArr['totalAmounts'] += $amount_used_Arr[$gameid];
                    }
                }
                if (intval($maxamount_Arr['6h']) < $amount_Arr['6h'])
                {
                    diemsg(L_CREDITOVER);
                }
                /*if ($g_init_mode_3d && intval($maxamount_Arr['3d']) < $amount_Arr['3d'])
                {
                    diemsg("3D彩 " . L_CREDITOVER);
                }
                if ($g_init_mode_3d && intval($maxamount_Arr['3s']) < $amount_Arr['3s'])
                {
                    diemsg("时时彩 " . L_CREDITOVER);
                }*/
                $rs0 = getdb("select * from k_user where acl=" . $acl . " and id=" . $id);
                if ($rs0->eof)
                {
                    diemsg(L_WRONGAGENTID);
                }
                if ($g_init_mode_6h && $psen_edit_mod_Arr[0] == 0 && $amount_used_Arr[0] && $amount_Arr['6h'] < $amount_used_Arr[0])
                {
                    diemsg("该会员在本期的 六合彩 已有投注，在开盘期间信用额度不得低於：" . $amount_used_Arr[0]);
                }
                if ($g_init_mode_3d && $chk3DFlagArr['totalAmounts'] && $amount_Arr['3d'] < $chk3DFlagArr['totalAmounts'])
                {
                    diemsg("该会员在本期的 福体彩 已有投注，在开盘期间信用额度不得低於：" . $chk3DFlagArr['totalAmounts']);
                }
                if ($g_init_mode_3d && $chk3SFlagArr['totalAmounts'])
                {
                    if ($amount_Arr['3s'] < $rs0->f['amount_3s1'])
                    {
                        diemsg("该会员在本期的 时时彩 已有投注，在开盘期间不可调降信用额度。");
                    }
                    $amount_type_mod_chg_flag = false;
                    if ($rs0->f['amount_type'] != $amount_type)
                    {
                        $amount_type_mod_chg_str = "<br /><font color=red>该会员时时彩已有下注,无法异动浮动额度设定值</font>";
                    }
                }
                if ($amount_type_mod_chg_flag && $rs0->f['amount_type'] == 1 && $amount_type == 0)
                {
                    include_once( "class_3d/Amounts_float_3d.php" );
                    $Amounts_float_3d = new Amounts_float_3d();
                    $totalFloatAmount = $Amounts_float_3d->getAmountFloat($id, 3);
                    if ($totalFloatAmount != 0)
                    {
                        $amount_type_mod_chg_flag = false;
                        $amount_type_mod_chg_str = "<br /><font color=red>该会员的储值额度加总不为 0,无法异动浮动额度设定值</font>";
                    }
                }
                $ins_diskmod = array();
                $ins_diskmod[1] = $disk_chg->trans_on(getvar("disk1mod"));
                $ins_diskmod[2] = $disk_chg->trans_on(getvar("disk2mod"));
                $ins_diskmod[3] = $disk_chg->trans_on(getvar("disk3mod"));
                $ins_diskmod[4] = $disk_chg->trans_on(getvar("disk4mod"));
                $disk_data = array("id" => $id, "acl" => $acl, "prev_id" => $prev_id, "disk1" => $ins_diskmod[1], "disk2" => $ins_diskmod[2], "disk3" => $ins_diskmod[3], "disk4" => $ins_diskmod[4]);
                if ($disk_chg->Check_disk($disk_data) == FALSE)
                {
                    diemsg("盘类设定有误，请确认！");
                }
                $sql = "update k_user set name='" . $name . "'" . ", updatedt='" . systime() . "',disabled='" . $mbr_disabled_chk . "'";
                $sql .= ", disk1='" . $ins_diskmod[1] . "'";
                $sql .= ", disk2='" . $ins_diskmod[2] . "'";
                $sql .= ", disk3='" . $ins_diskmod[3] . "'";
                $sql .= ", disk4='" . $ins_diskmod[4] . "'";
				$sql .= ", amount=" . $amount_Arr['6h'];
				if(floatval($amount_Arr['6h'])!=floatval($rs0->f['amount'])){
					if($amount_type==0) //信用每天还原
					{
						$balance=floatval($amount_Arr['6h'])-floatval($rs0->f['amount']);
					}
					else
					{
						$balance=floatval($amount_Arr['6h'])-floatval($rs0->f['amount']);
					}
					$sql .= ", balance=balance+" . $balance;
				}
                /*if ($amount_used_Arr[0] <= $amount_Arr['6h'])
                {
                    $sql .= ", amount=" . $amount_Arr['6h'];
                }
                if ($amount_used_Arr[1] + $amount_used_Arr[2] <= $amount_Arr['3d'])
                {
                    $sql .= ", amount_3d=" . $amount_Arr['3d'];
                }
                if ($amount_Arr['3s'] != $rs0->f['amount_3s1'])
                {
                    $sql .= ", amount_3s1=" . $amount_Arr['3s'];
                }*/
                if ($psen_edit_mod_Arr[0] && $g_init_mode_6h)
                {
                    $sql .= ", rate0=" . $rate0;
                }
                if ($amount_type_mod_chg_flag)
                {
                    $sql .= ", amount_type=" . $amount_type;
                }
                if ($pass != "")
                {
                    $sql .= ", pass='" . md5($pass) . "', chgpwdt = 0";
                }
                $sql .= " where acl=" . $acl . " and id=" . $id;
                getdb($sql);
                $amtIdx_Arr = array("6h" => "amount", "3d" => "amount_3d", "3s" => "amount_3s1");
                $gameId_Arr = array("6h" => 0, "3d" => 1, "3s" => 10);
                foreach ($amtIdx_Arr as $idx => $amount_field_name)
                {
                    if ($amount_Arr[$idx] != $rs0->f[$amount_field_name])
                    {
                        $sql = "insert modifybook (dt,account1,name1,acl1,account2,name2,acl2,modify,percent_mode,amount_old,amount_new) values (" . ( "'" ) . systime() . "'" . ",'" . $u_prev['account'] . "'" . ",'" . $u_prev['name'] . "'" . ",2" . ",'" . $rs0->f['account'] . "'" . ",'" . $rs0->f['name'] . "'" . ",1" . ",'" . $aclname[$curruser['acl']] . "'" . "," . $gameId_Arr[$idx] . "," . $rs0->f[$amount_field_name] . "," . $amount_Arr[$idx] . ")";
                        getdb($sql);
                    }
                }
                $rs0->close();
                $userdata = get_user($id);
                if ($userdata['enabled'] != $enabled)
                {
                    if ($enabled == 1)
                    {
                        if ($member_limit < $tot_acl_1)
                        {
                            diemsg("本系统可启用的会员资料空间已满！");
                        }
                        if (!$user->enable($id))
                        {
                            $tpl->set("memo", "<font color=red>" . $g_cache['user_error']['string'] . "</font>");
                        }
                    }
                    else
                    {
                        if ($enabled == 2)
                        {
                            $user->pause($id);
                        }
                        else
                        {
                            if ($enabled == 0)
                            {
                                if (0 < array_sum($amount_used_Arr))
                                {
                                    diemsg("此位会员在本期已经有投注，在本日结束之前不得停用此位会员！");
                                }
                                else
                                {
                                    $user->disable($id);
                                }
                                $rs->close();
                            }
                        }
                    }
                }
            }
            else
            {
				
                if ($member_limit < $tot_acl_1)
                {
                    diemsg("本系统可建立的会员资料空间已满！");
                }
                $pass = getvar("pass");
                if (G_ACCOUNT == 0)
                {
                    if ($account == "")
                    {
                        diemsg(L_INPUTACCOUNT);
                    }
                    if (!ctype_alnum($account))
                    {
                        diemsg("帐号只能输入A-Z,a-z,0-9的字元！");
                    }
                    if (substr($account, 0, 1) != "d")
                    {
                        diemsg("会员帐号前置码必需为 d ");
                    }
                    if (strlen($account) < 4)
                    {
                        diemsg("帐号需要四码以上");
                    }
                    if (!check_account_legal($account))
                    {
                        diemsg("帐号必须为６个以上的英文字母及数字混和所组成！（请注意英文大小写）");
                    }
                    if ($pass == "")
                    {
                        diemsg(L_INPUTPWD);
                    }
                    if (!ctype_alnum($pass))
                    {
                        diemsg("密码只能输入A-Z,a-z,0-9的字元！");
                    }
                    if (!check_account_legal($pass))
                    {
                        diemsg("密码必须为６个以上的英文字母及数字混和所组成！（请注意英文大小写）");
                    }
                }
                else
                {
                    $account = chk_account($account);
                    $pass = chk_pass($pass);
                    if (substr($account, 0, 3) != substr($u_prev['account'], 0, 3))
                    {
                        diemsg(L_ACCOUNTTHREE . substr($u_prev['account'], 0, 3) . " !");
                    }
                }
                $rs = getdb("select * from k_user where account='" . $account . "'");
                if (!$rs->eof)
                {
                    diemsg(L_ACCOUNTDUPLICATION);
                }
                if ($psen_edit_mod_Arr[0] == 1)
                {
                    $rate0 = 0;
                }
                $disk1mod = 0;
                if (getvar("disk1mod"))
                {
                    $disk1mod = 1;
                }
                $disk2mod = 0;
                if (getvar("disk2mod"))
                {
                    $disk2mod = 1;
                }
                $disk3mod = 0;
                if (getvar("disk3mod"))
                {
                    $disk3mod = 1;
                }
                $disk4mod = 0;
                if (getvar("disk4mod"))
                {
                    $disk4mod = 1;
                }
                $ins_diskmod = array();
                $ins_diskmod[1] = $disk_chg->trans_on(getvar("disk1mod"));
                $ins_diskmod[2] = $disk_chg->trans_on(getvar("disk2mod"));
                $ins_diskmod[3] = $disk_chg->trans_on(getvar("disk3mod"));
                $ins_diskmod[4] = $disk_chg->trans_on(getvar("disk4mod"));
                $disk_data = array("id" => $id, "acl" => $acl, "prev_id" => $prev_id, "disk1" => $ins_diskmod[1], "disk2" => $ins_diskmod[2], "disk3" => $ins_diskmod[3], "disk4" => $ins_diskmod[4]);
                if ($disk_chg->Check_disk($disk_data) == FALSE)
                {
                    diemsg("盘类设定有误，请确认！");
                }
                $data = array("acl" => $acl, "enabled" => "1", "account" => QuotedStr($account), "pass" => QuotedStr(md5($pass)), "name" => QuotedStr($name), "disk1" => $ins_diskmod[1], "disk2" => $ins_diskmod[2], "disk3" => $ins_diskmod[3], "disk4" => $ins_diskmod[4], "amount" => 0, "amount_3d" => 0, "amount_3s1" => 0, "createdt" => systime(), "prev_id" => $prev_id, "rate0" => $rate0, "amount_type" => $amount_type, "createAccount" => QuotedStr($curruser['account']), "disabled" => $mbr_disabled_chk);
				$ins_chk = db_insert("k_user", $data);
                if ($ins_chk == TRUE)
                {
                    $tpl->set("ins_chk", "ins");
                }
                else
                {
                    diemsg("! 建立失败！");
                }
                $sql = "!!select * from k_user where account='" . $account . "' and pass='" . md5($pass) . "'";
                $rs = getdb($sql);
                if (!$rs->eof)
                {
                    $id = $rs->f[0];
                    $copyMemAmountId = intval(getvar("copyMemAmountId"));
                    $copyMemAmountFlag = true;
                    if ($copyMemAmountId != 0)
                    {
                        $copyMemRS = getdb("!!SELECT id FROM k_user WHERE id={$copyMemAmountId} AND prev_id=" . $rs->f['prev_id']);
                        $copyMemAmountFlag = $copyMemRS->eof;
                    }
                    if ($copyMemAmountFlag)
                    {
                        foreach ($g_gametype_3d as $gameid => $val)
                        {
                            if ($g_init_mode_6h && $gameid == 0 && CreateAmount($id, 0) == false)
                            {
                                diemsg("建立该帐号的六合彩限额发生错误！");
                            }
                            else if ($g_init_mode_3d && $gameid && $g_menu_enabled[$gameid] && CreateAmount($id, $gameid) == false)
                            {
                                diemsg("建立该帐号的{$val['chs']}限额发生错误！");
                            }
                        }
                    }
                    else
                    {
                        foreach ($g_gametype_3d as $gameid => $val)
                        {
                            if ($g_init_mode_6h && $gameid == 0)
                            {
                                copyAmount($id, 0, $copyMemAmountId);
                            }
                            else if ($g_init_mode_3d && $gameid && $g_menu_enabled[$gameid])
                            {
                                copyAmount($id, $gameid, $copyMemAmountId);
                            }
                        }
                    }
                }
                else
                {
                    diemsg("错误的新增数据造成储存错误！");
                }
            }
        }
        $tpl->set("action", "?" . $_SERVER['QUERY_STRING']);
        $disk1_disab = "";
        $disk2_disab = "";
        $disk3_disab = "";
        $disk4_disab = "";
        $dk_check = $disk_chg->Browser($prev_id);
        if ($dk_check['disk1'] + $dk_check['disk2'] + $dk_check['disk3'] + $dk_check['disk4'] == 0)
        {
            diemsg("没有开放会员可下注的盘类，请联系您的上层管理员！");
        }
        if ($dk_check['disk1'] == 0)
        {
            $disk1_disab = "disabled";
        }
        if ($dk_check['disk2'] == 0)
        {
            $disk2_disab = "disabled";
        }
        if ($dk_check['disk3'] == 0)
        {
            $disk3_disab = "disabled";
        }
        if ($dk_check['disk4'] == 0)
        {
            $disk4_disab = "disabled";
        }
        $dk_browser = $id ? $disk_chg->Browser($id) : $dk_check;
        $alldisk_3d = "<tr><td class=td1>可用盘类</td><td class=td2>";
        if ($dk_browser['disk1'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk1mod checked> A 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk1mod {$disk1_disab}> A 盘.&#12288;";
        }
        if ($dk_browser['disk2'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk2mod checked> B 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk2mod {$disk2_disab}> B 盘.&#12288;";
        }
        if ($dk_browser['disk3'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk3mod checked> C 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk3mod {$disk3_disab}> C 盘.&#12288;";
        }
        if ($dk_browser['disk4'] == 1)
        {
            $alldisk_3d .= "<input type=checkbox name=disk4mod checked> D 盘.&#12288;";
        }
        else
        {
            $alldisk_3d .= "<input type=checkbox name=disk4mod {$disk4_disab}> D 盘.&#12288;";
        }
        $tpl->set("alldisk", $alldisk_3d);
        if (0 < $id)
        {
            $tpl->set("edit_disabled", "disabled");
            $rs = getdb("select * from k_user where acl=" . $acl . " and id=" . $id);
            if ($rs->eof)
            {
                diemsg(L_ERRMEMID);
            }
            $account = $rs->f['account'];
            $rs1 = getdb("select * from k_user where id=" . $rs->f['prev_id']);
            if ($curruser['acl'] == "255")
            {
                $disabled = "";
                if ($rs->f['disabled'] == 1)
                {
                    $disabled = "<input type='checkbox' name='mbr_disabled' CHECKED=checked> 禁止登入";
                }
                else
                {
                    $disabled = "<input type='checkbox' name='mbr_disabled'> 禁止登入";
                }
                $tpl->set("mbr_disabled_chk", $disabled);
            }
            $tpl->set("passdesc", "<br><font color=aaaaaa>" . L_INPUTCHGPWD . "</font>");
            $tpl->set("noeditaccount", "disabled");
            $tpl->set("account", $rs->f['account']);
            $tpl->set("name", $rs->f['name']);
            $tpl->set("id", $id);
            $tpl->set("enabled" . $rs->f['enabled'], "checked");
            $tpl->set("createdt", date("Y-m-d H:i:s", $rs->f['createdt']));
            $show3DAmounts = 0;
            $show3SAmounts = 0;
			$data_6h = array("", $rs->f['amount'], $maxamount_Arr['6h']);
			$tr="<tr><td class=paper6h>信用额度</td><td class=td2 colspan=3>\r\n\t\t<input maxlength='100' name='amount' value='".$rs->f['amount']."' size='10' onkeypress=\"return OnlyInt()\"\r\n\t\tonkeyup=\"document.all.camount.innerHTML=n2c(this.value)\">&#12288;
			<input type=checkbox style='display:none' name=amount_type " . ($rs->f['amount_type']=='1'?"checked":"") . " value=\"1\" onclick=\"javascript:showTrAmountsFloat(this);\">".($rs->f['amount_type']=='1'?"浮动额度":"信用额度")."&nbsp;&nbsp;&nbsp;<font color=red id=camount></font>\r\n\t\t
			<br><br><font color=red id=camount_3s1></font>● 会员目前可用额度(<font color=red>" . floatval($rs->f['balance']). "</font>)&nbsp;● 代理最大可用额度(<font color=red>" . $maxamount_Arr['6h'] . "</font>){$amount_type_mod_chg_str}</td></tr>";
			$tpl->set("amount", $tr);
            foreach ($g_gametype_3d as $gameid => $val)
            {
                if ($g_init_mode_6h)
                {
                    //if ($reat0_open)
                    //{
                    //    $tpl->set("reat0open", "<tr><td class=paper6h>六合彩特码减倍</tD><td class=td2><input name=rate0 value=" . $rs->f['rate0'] . " size=3 maxlength=4></td></tr>");
                    //}
                    $data_6h = array("6h", "六合彩", $u_prev_percent_Arr[$gameid]['mpercent']);
                    $tpl->set("mpsen", $stbl->percent($data_6h));
                }
                if ($g_init_mode_3d && $g_menu_enabled[$gameid] && $gameid==12)
                {
                    $data_3d = array($g_gametype_3d[$gameid]['en'], $g_gametype_3d[$gameid]['zc'], $u_prev_percent_Arr[$gameid]['mpercent']);
                    $tpl->set("mpsen_{$g_gametype_3d[$gameid]['en']}", $stbl->percent($data_3d));
                    if ($val['type'] == 1)
                    {
                        $show3DAmounts = 1;
                    }
                    else if (1 < $val['type'])
                    {
                        $show3SAmounts = 1;
                    }
                }
            }
            if ($show3DAmounts)
            {
                $data_3d = array("3D彩共用", "3d", $rs->f['amount_3d'], $maxamount_Arr['3d']);
                $tpl->set("amount_3d", $stbl->amount($data_3d));
            }
            $amount_type_mod = "";
            $showTrAmountFloat = "";
            if ($show3SAmounts)
            {
                if ($rs->f['amount_type'] == 1)
                {
                    $amount_type_mod = " checked";
                    $showTrAmountFloat = "";
                }
                else
                {
                    $amount_type_mod = "";
                    $showTrAmountFloat = "style=\"display:none\";";
                }
				/*$allMoney=0;
				$floatBack3s = intval($conf->get("floatBack_3s"));
				if ($floatBack3s)
					$floatBack3sStr = "";
				else
					$floatBack3sStr = "-a.a1";
				foreach($g_gametype_3d as $keys=>$v)
				{
					if($keys>=3)
					{
						$total_rs=getdb("select ifnull(sum(if(a.rame=0,-a.amount,a.b1".$floatBack3sStr.")),0) as c from bet_".$v['en']." a left join lotto_".$v['en']." b on b.id=a.lotto_id where a.user_id='$id' and b.open='".date('Y-m-d',time()-3*3600)."' and a.rame in (0,9)");
						$allMoney+=$total_rs->f['c'];	
					}
				}*/
				//$sumAmount = $Bet_3d->getSumAmount($curruser['id'], $lotto_id, $paperOpen);
				//echo $sumAmount;
                /*$list_3d = "<tr><td class=paper3d >时时彩共用信用额度</td><td class=td2><input maxlength=100 name=amount_3s1 value=" . $rs->f['amount_3s1'] . " size=10 onkeypress=\"return OnlyInt()\"\r\n\t\t\tonkeyup=\"document.all.camount_3s1.innerHTML=n2c(this.value)\">&#12288;<label><input type=checkbox style='display:none' name=amount_type" . $amount_type_mod . " value=\"1\" onclick=\"javascript:showTrAmountsFloat(this);\">".(trim($amount_type_mod)=="checked"?"浮动额度":"信用额度")."\r\n\t\t\t<a class='tooltips' href='#tooltips'>说明<span><div>※<strong>浮动额度操作方法</strong><br />
      ◎<strong style='color:red'>增加额度:</strong> 在左方文本框输入正值数额後按「储值」钮。会员增加额度後，会扣除代理的额度。<br />
      ◎<strong style='color:red'>减少额度:</strong> 在左方文本框输入正值数额後按「提取」钮。会员减少额度後，代理额度不变。<br />
      </div></span></a><br><br><font color=red id=camount_3s1></font>● 会员目前可用额度(<font color=red>" . round($rs->f['amount_3s1']+$allMoney,2). "</font>)&nbsp;● 代理最大可用额度(<font color=red>" . $maxamount_Arr['3s'] . "</font>){$amount_type_mod_chg_str}</td></tr>";
                $list_3d .= "<tr {$showTrAmountFloat} id=\"trAmountsFloat\"><td class=td1>储值纪录</td><td class=td2><a href=\"op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$id}\"><input type=\"button\" value=\"查看时时彩储值纪录\" id=\"btnAmountsFloat\" onclick=\"javascript:showAmountsFloatPage({$gametype},{$id});\" /></a></td></tr>";
                $tpl->set("amount_3s1", $list_3d);*/
            }
            if ($rs->f['updatedt'] != "")
            {
                $tpl->set("updatedt", date("Y-m-d H:i:s", $rs->f['updatedt']));
            }
            if ($rs->f['lastlogdt'] != "")
            {
                $tpl->set("lastlogdt", date("Y-m-d H:i:s", $rs->f['lastlogdt']));
                $tpl->set("lastlogip", $rs->f['lastlogip']);
            }
            $tpl->set("logcount", $rs->f['logcount']);
            $tmp = "";
            $tpl->set("del_user", $member_limit < $tot_acl_1 ? "&#12288;<font color=red>本系统可用的会员资料空间已满！</font>" : "" );
            $btnMymodifyStr = "<input type=button value=\"占成与信用额度异动记录\" onclick=\"javascript:showMymodifyPage({$gametype},'{$account}');\">";
            if (0 < $gametype)
            {
                switch ($curruser['acl'])
                {
                    case 255 :
                        $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick='location.replace(\"" . ( "?op=agent&fp=amount2_3d&gametype=" ) . $gametype . "&id=" . $id . "\")'> {$btnMymodifyStr} <input type=button value='阶层资料' onclick=\"  form_submit('2'); \" >");
                        $tpl->set("hy_gametype", $gametype);
                        $tpl->set("hy_account", $account);
                        break;
                    case 5 :
                        $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick='location.replace(\"" . ( "?op=agent&fp=amount2_3d&gametype=" ) . $gametype . "&id=" . $id . "\")'> {$btnMymodifyStr} <input type=button value='阶层资料' onclick=\"  form_submit('1'); \" >");
                        $tpl->set("hy_gametype", $gametype);
                        $tpl->set("hy_account", $account);
                        break;
                }
                $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick='location.replace(\"" . ( "?op=agent&fp=amount2_3d&gametype=" ) . $gametype . "&id=" . $id . "\")'> {$btnMymodifyStr} ");
            }
            else
            {
                switch ($curruser['acl'])
                {
                    case 255 :
                        $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick='location.replace(\"" . ( "?op=agent&fp=amount2_3d&gametype=" ) . $gametype . "&id=" . $id . "\")'> {$btnMymodifyStr} <input type=button value='阶层资料' onclick=\"  form_submit('2'); \" >");
                        $tpl->set("hy_gametype", $gametype);
                        $tpl->set("hy_account", $account);
                        break;
                    case 5 :
                        $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick='location.replace(\"" . ( "?op=agent&fp=amount2_3d&gametype=" ) . $gametype . "&id=" . $id . "\")'> {$btnMymodifyStr} <input type=button value='阶层资料' onclick=\"  form_submit('1'); \" >");
                        $tpl->set("hy_gametype", $gametype);
                        $tpl->set("hy_account", $account);
                        break;
                }
                $tpl->set("deletebutton", "<input type=button value=编辑限额 onclick='location.replace(\"" . ( "?op=agent&fp=amount2_3d&gametype=" ) . $gametype . "&id=" . $id . "\")'> {$btnMymodifyStr} ");
            }
        }
        else
        {
			$tpl->set("account_msg","");
			$list_3d = "<tr><td class=td1>选用额度</td><td class=td2 colspan=3><input type=radio value=0 checked name=amount_type>信用额度</font><input type=radio value=1 name=amount_type>浮动额度</font></td></tr>";
            $list_3d .= "<tr><td class=td1>额度使用说明</td><td class=td2 colspan=3>◎<strong style='color:red'>信用额度:</strong> 每日结帐後，会将额度「补回至初始额度」。<br />◎<strong style='color:red'>浮动额度:</strong> 如会员额度10万，今日输5万，隔日额度只会有五万。输完必须由上一个阶层对下阶层充值。</td></tr>";
			$tpl->set("amount_3s1", $list_3d);
            $tpl->set("enabled1", "checked");
            if (G_ACCOUNT == 0)
            {
                $tpl->set("account", "d");
            }
            else
            {
                $rs = getdb("select account from k_user where id='" . $prev_id . "'");
                $tpl->set("account", substr($rs->f['account'], 0, 3));
            }
            $tpl->set("del_user", $member_limit < $tot_acl_1 ? "&#12288;<font color=red>本系统可用的会员资料空间已满！</font>" : "" );
            $agentlist = "<select name='prev_id' id='slcPrevId'>";
            $rs9 = false;
            if ($curruser['acl'] == 255)
            {
                $rs9 = getdb("SELECT `id`,`account`,`name` FROM `k_user` WHERE `id`=" . intval(getvar("prev_id")) . "  limit 1");
            }
            else
            {
                $users9 = getuserlist($curruser['id'], 2);
                if ($users9 != "")
                {
                    $rs9 = getdb("select id,account,name from k_user where id in ({$users9}) and enabled=1 order by account");
                }
                else
                {
                    $rs9 = getdb("select id,account,name from k_user where acl=2 and enabled=1 order by account");
                }
            }
            if ($rs9)
            {
                while (!$rs9->eof)
                {
                    $slcOption = $prev_id == $rs9->f['id'] ? "selected" : "";
                    $agentlist .= "<option value='" . $rs9->f['id'] . "' {$slcOption}>" . $rs9->f['account'] . " (" . $rs9->f['name'] . ")</option>";
                    $rs9->movenext();
                }
                $rs9->close();
            }
            $agentlist .= "</select>";
            $agentlist .= "&nbsp;复制会员&nbsp;";
            $agentlist .= "<select name='copyMemAmountId' id='copyMemAmount'></select>";
            $tpl->set(array("action" => "?op=agent&fp=member&gametype={$gametype}&cmd=add", "gametype" => $gametype));
        }
        if (isset($agentlist))
        {
            $tmp = "<tr><td class=td1>" . L_AGENT . "<td class=td2>" . $agentlist;
        }
        else
        {
            $tmp = "<tr><td class=td1>" . L_AGENT . "<td class=td2>" . $u_prev['account'];
            $tmp .= "<input type=hidden name=prev_id value=" . $prev_id . ">";
        }
        $tpl->set("agentlist", $tmp);
        $tpl->set("submit", 0 < $id ? L_OK : L_ADD );
        $tpl->show("main");
        if (isset($agentlist))
        {
            $tpl->load("main_js", "member_js.htm");
            $tpl->show("main_js");
        }
    }
}

function copyAmount ($id, $gametype, $copyID)
{
    global $g_betname;
    global $g_betname_3d;
    global $g_betname_3s;
    global $g_betname_5h;
    global $g_gametype_3d;
    $gmode = $gametype ? "_" . $g_gametype_3d[$gametype]['en'] : "";
    if ($gmode == "")
    {
        $betname = $g_betname;
    }
    else if ($g_gametype_3d[$gametype]['type'] == 3)
    {
        $betname = $g_betname_5h[$gametype];
    }
    else
    {
        $betname = judge_type($gametype);
    }
    $info = get_user($id);
    if ($info['acl'] != 1)
    {
        return;
    }
    else
    {
        $u1 = GetAmountSetting($info['prev_id'], $gametype, 1);
        $u2 = GetAmountSetting($copyID, $gametype, 1);
        foreach ($betname as $key => $val)
        {
            if ($gmode == "" && ( $key == 27 || $key == 36 ))
            {
                $begin = 2;
                $end = $key == 27 ? 5 : 4;
                $i = $begin;
                while ($i <= $end)
                {
                    $keyi = $key . $i;
                    $back = 100;
                    if ($info['acl'] == 1 && $gmode == "")
                    {
                        $backTempIdx = "back" . $info['disk'];
                        $backTemp = max($u1[$keyi][$backTempIdx], $u2[$keyi][$backTempIdx]);
                        if ($back == 100)
                        {
                            $back = $backTemp;
                        }
                        else if ($back < $backTemp)
                        {
                            $back = $backTemp;
                        }
                    }
                    $sql = "insert into amounts (" . ( "user_id,bettype,subid,amount1,amount2,avail,back,back1,back2,back3,back4,auto_nt" ) . ") values (" . $id . "," . $key . ",{$i}," . min($u1[$keyi][1], $u2[$keyi][1]) . "," . min($u1[$keyi][2], $u2[$keyi][2]) . ",0," . $back . "," . max($u1[$keyi]['back1'], $u2[$keyi]['back1']) . "," . max($u1[$keyi]['back2'], $u2[$keyi]['back2']) . "," . max($u1[$keyi]['back3'], $u2[$keyi]['back3']) . "," . max($u1[$keyi]['back4'], $u2[$keyi]['back4']) . ",0)";
                    getdb($sql);
                    ++$i;
                }
            }
            $back = 100;
            if ($g_gametype_3d[$gametype]['type'] == 3)
            {
                $sql = "insert into amounts{$gmode} (" . "user_id,bettype,subid,amount1,amount2,avail,back,back1,back2,back3,back4,auto_nt" . ") values (" . $id . "," . $key . ",0," . min($u1[$key][1], $u2[$key][1]) . "," . min($u1[$key][2], $u2[$key][2]) . ",0," . $back . "," . max($u1[$key]['back1'], $u2[$key]['back1']) . "," . max($u1[$key]['back2'], $u2[$key]['back2']) . "," . max($u1[$key]['back3'], $u2[$key]['back3']) . "," . max($u1[$key]['back4'], $u2[$key]['back4']) . ",0)";
                getdb($sql);
            }
            else if ($gmode != "")
            {
                $keyArr = explode("_", $key);
                $sql = "insert into amounts{$gmode} (" . "user_id,bettype,subid,amount1,amount2,avail,back,back1,back2,back3,back4,auto_nt" . ") values (" . $id . "," . $keyArr[0] . ",{$keyArr[1]}," . min($u1[$key][1], $u2[$key][1]) . "," . min($u1[$key][2], $u2[$key][2]) . ",0," . $back . "," . max($u1[$key]['back1'], $u2[$key]['back1']) . "," . max($u1[$key]['back2'], $u2[$key]['back2']) . "," . max($u1[$key]['back3'], $u2[$key]['back3']) . "," . max($u1[$key]['back4'], $u2[$key]['back4']) . ",0)";
                getdb($sql);
            }
            else
            {
                $sql = "insert into amounts{$gmode} (" . "user_id,bettype,amount1,amount2,avail,back,back1,back2,back3,back4,auto_nt" . ") values (" . $id . "," . $key . "," . min($u1[$key][1], $u2[$key][1]) . "," . min($u1[$key][2], $u2[$key][2]) . ",0," . $back . "," . max($u1[$key]['back1'], $u2[$key]['back1']) . "," . max($u1[$key]['back2'], $u2[$key]['back2']) . "," . max($u1[$key]['back3'], $u2[$key]['back3']) . "," . max($u1[$key]['back4'], $u2[$key]['back4']) . ",0)";
                getdb($sql);
            }
        }
    }
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
if ($curruser['acl'] == 255 && $curruser['prev_id'] != 0 && !SubAccountRight($curruser, 2))
{
    exit();
}
if (isset($_SESSION['subaccount']) && $curruser['acl'] < 255)
{
    exit();
}
if ($curruser['enabled'] == 2)
{
    exit();
}
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
if ($chkGametype)
{
    include_once( "class_3d/CheckMode_3d.php" );
    $chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
    $chk->checkShow3dPage();
    unset($chk);
    $ui = new UI_3D(true, "报表管理");
    $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>" . ( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" );
    $ui->set("jslink", $jslink);
    $ui->header();
}
else
{
    $ui = new UI(true, "报表管理");
}
$conf = new Config();
$acl = 1;
$prev_id_post = intval(getvar("prev_id"));
$funlist = "<a href=\"?op=agent&fp=member&gametype={$gametype}&cmd=list&enabled=1&prev_id={$prev_id_post}\">" . L_ENABLEDLIST . "</a>" . " &nbsp; <a href=\"?op=agent&fp=member&gametype={$gametype}&cmd=list&enabled=0&prev_id={$prev_id_post}\">" . L_DISABLEDLIST . "</a>";
switch (getvar("cmd"))
{
    case "add" :
        $funlist .= " &nbsp; <a href=\"javascript:history.back()\">回上一页</a>";
        member_edit($gametype);
        break;
    case "edit" :
        $funlist .= " &nbsp; <a href=\"javascript:history.back()\">回上一页</a>";
        member_edit($gametype);
        break;
    default :
        $funlist .= " &nbsp; <a href=\"?op=agent&fp=member&gametype={$gametype}&cmd=add&prev_id={$prev_id_post}\">" . L_ADD . "</a>";
        member_list($gametype);
        break;
}
echo "</table>";
$ui->footer();
?>